package com.framework.controller;

import com.framework.entity.sys.SysBank;
import com.framework.exception.util.RespResult;
import com.framework.service.BankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 功能描述: 银行卡信息控制器
 *
 * @author ck
 * @date 2018/9/18 11:48
 */
@RestController
@Api(value="银行卡信息模块",tags={"银行卡信息模块"})
@RequestMapping(value = "bank")
public class BankController {

	@Autowired
	private BankService bankService;

	/**
	 * 查询银行卡信息列表
	 * @param token
	 * @return
	 */
	@GetMapping("user/queryBankList")
	@ApiOperation("获取当前人银行卡信息列表")
	public RespResult queryBankList(String token) {
		List<SysBank> list = bankService.queryBankList(token);
		return RespResult.ok().put("bank_list",list);
	}

	/**
	 * 添加银行卡信息
	 * @param bank 地址对象
	 * @param vCode 验证码
	 * @param token 登录人token
	 * @return
	 */
	@PostMapping("user/insertBank")
	@ApiOperation("添加银行卡信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name="vCode",value="验证码",dataType="string", paramType = "query" ,required = true)
	})
	public RespResult insertBank(SysBank bank, String vCode, String token) {
		bankService.insertBank(bank,vCode,token);
		return RespResult.ok();
	}

	/**
	 * 修改银行卡信息
	 * @param bank 对象地址
	 * @param vCode 验证码
	 * @param token 登录人token
	 * @return
	 */
	@PostMapping("user/updateBank")
	@ApiOperation("修改银行卡信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name="vCode",value="验证码",dataType="string", paramType = "query" ,required = true),
			@ApiImplicitParam(name="bankId",value="银行卡id",dataType="long", paramType = "query" ,required = true)
	})
	public RespResult updateBank(SysBank bank,String vCode,String token) {
		bankService.updateBank(bank,vCode,token);
		return RespResult.ok();
	}

	/**
	 * 获取银行卡详情
	 * @param token 登录人token
	 * @param bankId 银行卡id
	 * @return
	 */
	@GetMapping("user/infoBankById")
	@ApiOperation("获取银行卡详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name="bankId",value="银行卡id",dataType="long", paramType = "query" ,required = true),
	})
	public RespResult infoBankById(String token,Long bankId) {
		SysBank info = bankService.infoBank(token,bankId);
		return RespResult.ok().put("bank",info);
	}

	/**
	 * 删除银行卡信息
	 * @param bankId 银行卡id
	 * @return
	 */
	@PostMapping("user/delBankById")
	@ApiOperation("删除银行卡信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name="bankId",value="银行卡id",dataType="long", paramType = "query" ,required = true),
	})
	public RespResult delBankById(Long bankId) {
		bankService.delBank(bankId);
		return RespResult.ok();
	}

}
